function getMyAjax(){
    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option = {
        type:"post",
        data:"uid=" + myuid + "&year=" + $("#yearSelct").val(),
        dataType:"json",
        success:function(msg) {
            showMyReport(msg.list);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }

    };
    $.ajax(ip + "report/fenxitypezhidata",option);
}
function showMyReport(param) {

    var arr = param;
    var data = param;
    var nameArr = [];
    for (var i = 0 ; i < arr.length ; i++){
        nameArr.push(arr[i].name);
        if (arr[i].value==null){
            data[i].value=0;

        }

    }

    var year_option = {
        title : {
            text: '我的消费情况分析',
            subtext: '单位:元',
            x:'center'
        },
        backgroundColor: '#fff',

        tooltip: {
            show: true,
            trigger: 'item',
            formatter: "{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data:nameArr
        },
        series: [{
            type: 'pie',
            selectedMode: 'single',

            itemStyle:{
                normal:{
                    color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                }
            },

            radius : '55%',
            center: ['50%', '60%'],
            labelLine: {
                normal: {
                    show: true
                }
            },
            data: data
        }]
    };

    var myChart = echarts.init(document.getElementById('shouzhi_analyse'));
    myChart.setOption(year_option);
}

function getAvgAjax(){
    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option = {
        type:"post",
        data:"year=" + $("#yearSelct").val(),
        dataType:"json",
        success:function(msg) {
            showAvgReport(msg.list);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }

    };
    $.ajax(ip + "report/fenxitypezhiavgdata",option);
}
function showAvgReport(param) {

    var arr = param;
    var data = param;
    var nameArr = [];
    for (var i = 0 ; i < arr.length ; i++){
        nameArr.push(arr[i].name);
        if (arr[i].value==null){
            data[i].value=0;

        }

    }

    var year_option = {
        title : {
            text: '用户平均消费情况分析',
            subtext: '单位:元',
            x:'center'
        },
        backgroundColor: '#fff',

        tooltip: {
            show: true,
            trigger: 'item',
            formatter: "{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data:nameArr
        },
        series: [{
            type: 'pie',
            selectedMode: 'single',

            itemStyle:{
                normal:{
                    color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                }
            },

            radius : '55%',
            center: ['50%', '60%'],
            labelLine: {
                normal: {
                    show: true
                }
            },
            data: data
        }]
    };

    var myChart = echarts.init(document.getElementById('shouzhi_analyse_avg'));
    myChart.setOption(year_option);
}


$(function () {

    getMyAjax();

    getAvgAjax();

   $("#yearSelct").change(function () {
       getMyAjax();

       getAvgAjax();
   });

})